home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Text and Fonts / BoldAndItalicTighter / BoldAndItalicTighter.cs next >
Encoding:
Text File  |  2001-01-15  |  1.8 KB  |  50 lines

  1. //---------------------------------------------------
  2. // BoldAndItalicTighter.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Text;
  7. using System.Windows.Forms;
  8.  
  9. class BoldAndItalicTighter: PrintableForm
  10. {
  11.     public new static void Main()
  12.     {
  13.         Application.Run(new BoldAndItalicTighter());
  14.     }
  15.     public BoldAndItalicTighter()
  16.     {
  17.         Text = "Bold and Italic (Tighter)";
  18.         Font = new Font("Times New Roman", 24);
  19.     }
  20.     protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  21.     {
  22.         const string str1        = "This is some ";
  23.         const string str2        = "bold";
  24.         const string str3        = " text, and this is some ";
  25.         const string str4        = "italic";
  26.         const string str5        = " text.";
  27.         Brush        brush       = new SolidBrush(clr);
  28.         Font         fontRegular = Font;
  29.         Font         fontBold    = new Font(fontRegular, FontStyle.Bold);
  30.         Font         fontItalic  = new Font(fontRegular, FontStyle.Italic);
  31.         PointF       ptf         = new PointF(0, 0);
  32.         StringFormat strfmt      = StringFormat.GenericTypographic;
  33.         strfmt.FormatFlags      |= StringFormatFlags.MeasureTrailingSpaces;
  34.  
  35.         grfx.DrawString(str1, fontRegular, brush, ptf, strfmt);
  36.         ptf.X += grfx.MeasureString(str1, fontRegular, ptf, strfmt).Width;
  37.  
  38.         grfx.DrawString(str2, fontBold, brush, ptf, strfmt);
  39.         ptf.X += grfx.MeasureString(str2, fontBold, ptf, strfmt).Width;
  40.  
  41.         grfx.DrawString(str3, fontRegular, brush, ptf, strfmt);
  42.         ptf.X += grfx.MeasureString(str3, fontRegular, ptf, strfmt).Width;
  43.  
  44.         grfx.DrawString(str4, fontItalic, brush, ptf, strfmt);
  45.         ptf.X += grfx.MeasureString(str4, fontItalic, ptf, strfmt).Width;
  46.  
  47.         grfx.DrawString(str5, fontRegular, brush, ptf, strfmt);
  48.     }
  49. }
  50.